package com.gitee.wsl.common.ui.symbol

import androidx.annotation.FloatRange
import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.DrawScope.Companion.DefaultBlendMode
import androidx.compose.ui.graphics.drawscope.DrawStyle
import androidx.compose.ui.graphics.drawscope.Fill
import androidx.compose.ui.graphics.drawscope.translate
import com.gitee.wsl.common.ui.api.LocationAble
import com.gitee.wsl.common.ui.base.Point

interface Symbol{
    companion object
}

interface LocationSymbol:Symbol,LocationAble

open class SymbolLocation<T:Symbol>(
    override var position: Point,
    val symbol: T
):LocationAble

enum class SymbolStyle {
    Circle, Cross, Diamond, Square, Star, Triangle, Wye;
}

fun SymbolStyle.readerPath(path: Path, position: Point, radius: Float){
    when(this){
        SymbolStyle.Circle -> Symbol.circle(position,radius).also { path.circle(it) }
        SymbolStyle.Cross -> Symbol.cross(position,radius).also { path.cross(it) }
        SymbolStyle.Diamond -> path.diamond(Diamond(position,radius))
        SymbolStyle.Square -> Symbol.square(position,radius).also { path.square(it) }
        SymbolStyle.Star -> Symbol.star(position,radius).also { path.star(it) }
        SymbolStyle.Triangle -> path.triangle(position,radius)
        SymbolStyle.Wye -> Symbol.wye(position,radius).also { path.wye(it) }
    }
}

fun DrawScope.drawSymbol(
    symbol: SymbolStyle,
    position: Point,
    radius: Float,
    brush: Brush,
    @FloatRange(from = 0.0, to = 1.0) alpha: Float = 1.0f,
    style: DrawStyle = Fill,
    colorFilter: ColorFilter? = null,
    blendMode: BlendMode = DefaultBlendMode
){
    val path = Path()
    symbol.readerPath(path,Point.Zero,radius)
    this.translate(position.x,position.y){
        drawPath(path,brush,alpha,style,colorFilter,blendMode)
    }
}